<?php

/**
 * @category   Zhishidi daily deals
 * @package    Zhishidi_dailydeals
 * @author     ketu.lai
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
class Zhishidi_Question_Block_List extends Mage_Core_Block_Template {
    const XML_DAILY_DEALS_MODEL_PATH = 'zhishidi_dailydeals/settings';
    protected $_priceBlock = array();
    protected $_block = 'catalog/product_price';
    protected $_priceBlockDefaultTemplate = 'catalog/product/price.phtml';
    protected $_tierPriceDefaultTemplate = 'catalog/product/view/tierprices.phtml';
    protected $_priceBlockTypes = array();

    protected function _construct() {
        parent::_construct();
    }

    public function getContent($content) {
        $processor = Mage::getModel('core/email_template_filter');
        $content = $processor->filter($content);
        return $content;
    }

    public function loadQuestionCollection() {
        $collection = Mage::getModel('zhishidi_question/question')->getCollection()
                        ->addFieldToFilter('status', 'public')
                        ->addFieldToFilter('answered_on', array('notnull' => true))
                        ->addFieldToFilter('product_id', Mage::registry('product')->getId())
                        ->addFieldToFilter('store_id', Mage::app()->getStore()->getId());
        #echo $collection->getSelect()->__toString();

        return $collection;
    }

    protected function _prepareLayout() {


        $pager = $this->getLayout()->createBlock('page/html_pager', 'productqa.pager');
        $pager->setAvailableLimit(array(5 => 5, 10 => 10, 20 => 20, 50 => 50));
        $pager->setCollection($this->loadQuestionCollection());

        $this->setChild('pager', $pager);

        parent::_prepareLayout();
    }

    public function getPagerHtml() {
        return $this->getChildHtml('pager');
    }

    protected function getSettings() {
        return Mage::getModel(self::XML_DAILY_DEALS_MODEL_PATH);
    }

}